<template>
  <section class="container">
    
  
    <ft-table
      ref="gatewayTable"
      :data="gatewayData"
      :columns="gatwayColumns"
      :cell-style="{background: 'rgba(84, 92, 100, 0.25)'}"
    >
      <template #operation="{ row }">
        <el-button type="text" @click="gatewayDetails(row)">详情</el-button>
      </template>
    </ft-table>
  </section>
</template>

<script>
import {
  gatewayApi,
} from '@/api/setting.js'

import {mapGetters} from 'vuex';

export default {
  name: 'home',
  data(){
    return {
      gatwayColumns:[
        { prop: "name", label: "网关名称", align: "center" },
        { prop: "sn", label: "SN码", align: "center" },
        { prop: "ip", label: "ip", align: "center" },
        { prop: "operation", label: "操作", align: "center", slot: true },
      ],
      gatewayData: [],
    }
  },
  compouted: {
    ...mapGetters(['userInfo'])
  },
  mounted(){
  this.refreshGateway();
    if(this.userInfo.uid) this.refreshGateway();
  },
  methods: {
  
    refreshGateway(data){
      gatewayApi(data).then(res=>{
        if(res.code == 0){
          this.gatewayData = res.data;
        }
      })
    },
    gatewayDetails(row){
      this.$store.dispatch('SET_GATEWAY', row)
      localStorage.setItem('baseURL', row.ip + ':' + row.port)
      let path = 'rtd'
      // if(this.userInfo.is_admin == 1) path = 'gateway'
      this.$router.push( path )
    }
  }
}
</script>
